<?php
include(dirname(__DIR__).'/code/ControllerBase.class.php');

class UserController extends ControlBase{

    public function index(){
        echo "Hello";
    }

    //测试view
    public function hello(){
        $this->assign('data','helloWorld');
        $this->assign('persion','cateCat');
        $this->assign('pai',3.14);
        $arr=array(1,2,3,4,'hahatt',6);
        $this->assign('b',$arr);
        $this->show('hello');
    }

    //测试model
    public function testFind(){
        print_r(M('user')->where(array('id'=>1))->find());
        echo '<br/>';
        echo M('user')->getLastSql();
    }

    public function testSelect(){
        print_r(M('user')->find());
        echo '<br/>';

        echo M('user')->getLastSql();
    }

    public  function testUpdate(){
        M('user')->where(array('id'=>2))->save(array('password'=>'666666'));
        echo M('user')->getLastSql();
        echo '<br/>';
        print_r(M('user')->where(array('id'=>2))->find());
    }

    public  function testAdd(){
        M('user')->add(array('name'=>'bingbing','password'=>'pwd'));
        echo M('user')->getLastSql();
        echo "</br>";
        print_r(M('user')->select());
    }

    public  function testDelete(){
        M('user')->where(array('id'=>3))->delete();
        echo M('user')->getLastSql();
        echo "</br>";
        print_r(M('user')->select());
    }


    //testMVC
    public function testMVC(){
        $users=M('user')->select();

        $this->assign('users',$users);
        $this->show('testMVC');
    }

}
?>